#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 2e5 + 5;
int arr[N];

bool check(int x, int n, int k) {
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += (arr[i] > x ? x : arr[i]);
	}
	return (sum / k) >= x;
}

signed main()
{
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	int l = 0;
	int r = 1e15L;
	while (l < r) {
		int mid = ((r-l+1) >> 1) + l;
		if (!check(mid, n, k)) {
			r = mid - 1;
		} else {
			l = mid;
		}
	}
	cout << r << '\n';
	return 0;
}
